package com.Cfeng.XiaohuanChat.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author Cfeng
 * @date 2022/8/12
 * 用户上传的File
 */

//@Accessors(chain = true) BeanUtils
@EqualsAndHashCode  //hash的默认实现类
@Data
@Entity
public class UserFile implements Serializable {

    private static final long serialVersionUID = -4253748758962162702L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    //父文件ID，可以为目录
    @Column(nullable = false)
    private Long parentId;

    //文件原始名称
    @Column(nullable = false)
    private String fileName;

    //存储在minIO中文件对象名称UUID加密
    private String objectName;

    //文件路径
    private String url;

    //文件是否为文件夹,0否
    private Boolean isDir;

    //文件展示类型,后缀
    private String type;

    //文件是否图片，方便回显
    @Column(nullable = false)
    private Boolean isImg;

    //文件上传的时间
    @Column(nullable = false)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime uploadTime;

    //文件大小
    @Column(nullable = false)
    private Long fileSize;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnore //前台传输忽视
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    private ChatUser user;

    //不持久化，使用Transient
    //需要使用dirIds， 目录/文件ID ； 文件完整的目录
    @Transient
    private String dirIds;

    //文件/夹重命名后的值
    @Transient
    private String rename;
}
